st = input()
mx = 0
if len(st) == 4:
    a = [st[0], st[1], st[2], st[3], st[0:2], st[1:3], st[2:4], st[0:3], st[1:4], st]
    for i in range(len(a)):
        p = int(a[i])
        c = 2
        for t in range(2, p//+1):
            if p%t == 0:
                c+=1
        if c == 2 and p != 1:
            mx = max(mx, p)
print(mx)
